var windex = parent.layer.getFrameIndex(window.name);
$(function() {
		
	// 查询
	$('#btnQuery').on('click', function() {
		sys.reloadTable('customerTable');
	});
	
	//确定按钮点击事件
	/*$('#btnOK').on('click', function(){
		var selections = $('#customerTable').bootstrapTable('getSelections');
		if (selections.length == 0) {
			show("请至少选择一个客户");
			return false;
		}
		parent.CustomerId = selections[0].id;
		parent.CustomerName = selections[0].userName;
		parent.CompanyName = selections[0].companyInfo.companyName;
		parent.$('#layer_opt_status').val('1'); 
   		parent.layer.close(windex);
	})*/
	
	//取消按钮点击事件
	/*$('#btnCancel').on('click', function(){
   		parent.$('#layer_opt_status').val('0'); 
   		parent.layer.close(windex);
	})*/
	
	initCustomerGrid();
})

/**
 * 初始化用户信息列表
 */
function initCustomerGrid(){
	// 定义列
	var columns = [
	    { radio: true },
   		{ field : 'no', title : '序号', align : 'left',
   			formatter : function(value, row, index) {
   				return index + 1;
   			}
   		},
   		{ field : 'userName', title : '客户名称', align : 'center', valign:'middle' },
   		{ field : 'mobile', title : '手机号码', align : 'center', valign:'middle' },
   		{ field : 'companyInfo.companyName', title : '单位名称', align : 'center', valign:'middle' },
   		];
			
			
	// 定义查询回调函数（查询参数在此设置）
	var queryParams = function(params) {
		
		return {
			rows : params.limit, // 页面大小
			page : params.pageNumber, // 页码 
			"userName"	: $("#customerName").val(),
			"mobile"	: $("#mobile").val(),
			"companyInfo.companyName"	: $("#companyName").val(),  
		};
		
	};
	
	var url = rootPath + "/customer/listCustomerPage"; // 请求json数据的服务器地址
	sys.initTable('customerTable', {
		url : url,
		queryParams : queryParams,
		columns : columns,
		striped : true,
		clickToSelect : true,
		onCheck: function(row) {
			parent.CustomerId = row.id;
			parent.CustomerName = row.userName;
			parent.CompanyName = row.companyInfo.companyName;
			parent.$('#layer_opt_status').val('1'); 
	   		parent.layer.close(windex);
		}
	});
}
